﻿using System;
using System.Text;

namespace GPS.GPSLanguage
{
    public enum UnitType { Meter, Unknown };

    class Toolkit
    {
        internal static void ParseLatLong(out DirectionType dir, out int degrees, out double minutes, string latLongToken, string neswToken)
        {

            dir = DirectionTypeToken.ParseToken(neswToken);
            int dotLoc = latLongToken.IndexOf('.');
            degrees = 0;
            minutes = 0;

            try
            {
                if (dotLoc != -1 && latLongToken.Length > 0)
                {
                    degrees = int.Parse(latLongToken.Substring(0, dotLoc - 2));
                    minutes = double.Parse(latLongToken.Substring(dotLoc - 2));
                }
            }
            catch { }

        }

        internal static void ParseValAndUnit(out double val, out UnitType unitType, string altValToken, string altUnitTypeToken)
        {
            switch (altUnitTypeToken)
            {
                case "M":
                    unitType = UnitType.Meter;
                    break;
                default:
                    unitType = UnitType.Unknown;
                    break;
            }

            val = 0;
            try
            {
                if (altValToken.Length > 0)
                    val = double.Parse(altValToken);
            }
            catch { }

        }
    }
}
